import * as chalk from 'chalk';
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { ModelAppFactory } from './app';
import { AppModule } from './app.module';

async function bootstrap() {
  const modelAppFactory = ModelAppFactory.getInstance();
  const modelApp =  modelAppFactory.getActiveApp();
  const app = await NestFactory.create<NestFastifyApplication>(AppModule, new FastifyAdapter());
  await app.listen(modelAppFactory.port || 3000, '0.0.0.0');
  console.log(`${chalk.green('[IbizPlayer]')} Start success: ${chalk.green('%s')}`, '启动预览服务成功');
  console.log(`${chalk.green('[IbizPlayer]')} Port:   ${chalk.yellow(modelAppFactory.port || 3000)}`);
  if (modelApp && !modelApp.useLocalService) {
    console.log(`${chalk.green('[IbizPlayer]')} Info:  启用远端服务`);
    console.log(`${chalk.green('[IbizPlayer]')} Address:   ${modelApp.host}`);
  }
}
export const run = bootstrap;
// bootstrap()
